<template>
	<view>
		<!-- <van-sticky offset-top="0"> 
			<van-dropdown-menu>
				<van-dropdown-item v-model="value1" :options="option1" @change='change1' title='审批状态' />
				<van-dropdown-item v-model="value2" :options="typeColumns" @change='change2' title='类型'  />
				<van-dropdown-item v-model="value3" :options="option3" title='提交时间' @open='open3' />
			</van-dropdown-menu>
		</van-sticky> -->
		<view>
			<view v-for="(item,index) in list" :key="index" class="card" @click="routeTo(item)">
				<view class="createTime">
					<view class="typeName">{{item.definitionName}}</view>
					<view style="flex:1">
						<van-tag type="success" v-if="item.nowStatus=='PASS'">通过</van-tag>
						<van-tag type="danger" v-if="item.nowStatus=='REJECT'">未通过</van-tag>
						<van-tag color="#e1e1e1" v-if="item.nowStatus=='REVOKE'">撤销</van-tag>
						<van-tag type="primary" v-if="item.nowStatus=='PROCESSING'">审批中</van-tag>
					</view>
					<view class="time">{{item.createTime }}</view>
				</view>
				<view style="padding-bottom: 10rpx;">{{item.tip}} </view>
				<view v-if="item.definitionName=='调入调出'">
					<view class="time">转出单位：{{item.nowNodeTitle}}</view> 
					<view class="time">申请时间：{{item.createTime}}</view>
				</view>
				<view v-else>
					<view class="time">开始时间：{{ item.startTime }}</view>
					<view class="time">结束时间：{{ item.endTime }}</view>
				</view>
			</view>
		</view>
		<view v-if="total==0&&noData==true">

			<van-empty image-size="150" description="暂无记录" />
		</view>
		<!-- <view v-if="type==1">
			<view v-for="(item,index) in list" :key="index" class="card" @click="routeTo(item)">
				<view class="createTime">
					<view class="typeName">加班</view>
					<view style="flex:1">
						<van-tag type="success" v-if="item.nowStatus=='PASS'">通过</van-tag>
						<van-tag type="danger" v-if="item.nowStatus=='REJECT'">未通过</van-tag>
						<van-tag color="#e1e1e1" v-if="item.nowStatus=='CANCEL'">取消</van-tag>
						<van-tag type="primary" v-if="item.nowStatus=='PROCESSING'">审批中</van-tag>
					</view>
					<view class="time">{{item.createTime }}</view>
				</view>
				<view style="padding-bottom: 10rpx;">加班事由：{{ item.reason }} </view>
				<view class="time">开始时间：{{ item.startTime }}</view>
				<view class="time">结束时间：{{ item.endTime }}</view>
			</view>
		</view> -->

		<view style="height: 100rpx;"></view>

		<van-calendar v-model:show="showCalendar" @confirm="onConfirmDate" :min-date='minDater' :max-date="maxDate" />
	</view>
</template>
<script setup>
	import {
		onLoad,
		onReachBottom,
		onShow
	} from '@dcloudio/uni-app';
	import {
		dailyHolidayApproveList,
		dailyOverworkApproveList
	} from "@/api"
	import * as timeDeal from "@/utils/time.js"
	import { USER_INFO_KEY } from "@/enums/cacheEnum"
    const userInfo = ref(cache.get(USER_INFO_KEY))
	const minDater = ref(new Date(2000, 0, 1))
	const maxDate = new Date()
	const selectedDate = ref(null)
	const option1 = ref([{
			text: '通过',
			value: 'PASS'
		},
		{
			text: '未通过',
			value: 'REJECT'
		},
		{
			text: '审批中',
			value: 'PROCESSING'
		},
		{
			text: '撤销',
			value: 'REVOKE'
		},

	])
	const typeColumns = ref([{
			text: '请假',
			value: 'BIZ_DAILY_HOLIDAY_APPROVE'
		},
		{
			text: '加班',
			value: 'BIZ_DAILY_OVERWORK_APPROVE'
		},
		// {
		// 	text: '调入调出',
		// 	value: 'BIZ_DAILY_TRANSFER_APPROVE'
		// },
	])
	const option3 = ref([])
	const pageData = ref({
		current: 1,
		size: 10
	})
	const list = ref([])
	const value1 = ref(null) //审批状态
	const value2 = ref(null) //类型
	const value3 = ref('a')
	const keywords = ref('')
	const type = ref(0) //0请假  1加班
	const showCalendar = ref(false)
	const holidayTypeS = (event) => {
		console.log(event)
		let obj = typeColumns.value.find(v => {
			return v.value == event
		})
		return obj.text;
	}
	const noData = ref(true)
	const total = ref(0)
	onLoad(async (options) => {
		// const res = await getDictTreeApi()
		type.value = options.type
		// if (options.type == 0) {
		// 	getList()
		// } else {

		// }
		getOverworkList()
	})
	onShow(()=>{
		
	})
	const getList = () => {
		let data = {
			...pageData.value,
			nowStatus: value1 ? value1.value : '',
			flwCode: value2 ? value2.value : '',
		}
		dailyHolidayApproveList(data).then(res => {
			list.value = res.data.records
		})
	}
	const getOverworkList = () => {
		let data = {
			...pageData.value,
			nowStatus: value1.value ? value1.value : '',
			flwCode: type.value==0?'BIZ_DAILY_HOLIDAY_APPROVE':'BIZ_DAILY_OVERWORK_APPROVE',
			createTime_ge: selectedDate.value ? selectedDate.value + ' ' + '00:00:00' : '',
			createTime_le: selectedDate.value ? selectedDate.value + ' ' + '23:59:59' : '',
			createTime_desc:'createTime_desc',
			viewUsers_like:userInfo.value.id,
			flwCode_like:'BIZ_DAILY_HOLIDAY_APPROVE,BIZ_DAILY_OVERWORK_APPROVE'
		}
		dailyOverworkApproveList(data).then(res => {
			list.value = pageData.value.page == 1 ? res.data.records : list.value.concat(res.data.records)
			total.value = res.data.total
			noData.value = res.data.total > 0 ? false : true
			console.log(list.value)
		})
	}
	// 选择审批状态
	const change1 = (e) => {
		pageData.value.current == 1
		list.value = []
		getOverworkList()
	}
	// 选择请假类型
	const change2 = (e) => {
		pageData.value.current == 1
		list.value = []
		getOverworkList()
	}
	// 打开日历 
	const open3 = () => {
		showCalendar.value = true
	}
	const onConfirmDate = (e) => {
		selectedDate.value = timeDeal.formateDate(e, 'Y-M-D')
		showCalendar.value = false
		pageData.value.current == 1
		list.value = []
		getOverworkList()
	}
	const routeTo = (item) => {
		// let type= item.definitionName=='请假流程'?0:1
		if(item.definitionName=='调入调出'){ 
			uni.navigateTo({
				url: `/pages/mobilize/detail?id=${item.bizId}&type=${type}`
			})
		}else{
			uni.navigateTo({
				url: `/pages/vacation/detail?id=${item.bizId}&type=${type.value}`
			})
		}
		
	}
	onReachBottom(() => {
		if (total.value > list.value.length) {
			pageData.value.current = pageData.value.current + 1
			getOverworkList()
		}
	})
</script>
<style scoped lang="scss">
	.card {
		width: 690rpx;
		border-radius: 20rpx;
		margin: 20rpx auto;
		background: #fff;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		font-size: 28rpx;

		.typeName {
			font-weight: 600;
			font-size: 32rpx;
			margin-right: 20rpx;
		}

		.createTime {
			padding-bottom: 20rpx;
			display: flex;
			align-items: center;
		}

		.time {
			color: #8d8d8d;
			font-size: 24rpx;
		}
	}
</style>